﻿/*+===================================================================
File:      FlyItem.cpp

Summary:   Định nghĩa các phương thức của CFlyItem.
===================================================================+*/

#include "Explosion.h"
#include "PlayState.h"

CExplosion::CExplosion(D3DXVECTOR2 pos, int id, int typeID, bool isDamage, float timeLive)
	:CMoveableObject(pos, id, typeID)
{
	m_IsDamage = isDamage;

	m_box.width = 50.0f;
	m_box.height = 50.0f;
	switch (typeID)
	{
	case ID_SMALL_EXPLOSION:
		m_pSprite = new CSprite(*m_pResourceManager->GetSprite(ID_SPRITE_SMALL_EXPLOSION));
		if (timeLive == 0.0f)
			m_fTimeLive = 0.35f;
		else
			m_fTimeLive = timeLive;
		break;
	case ID_BIG_EXPLOSION:
		m_pSprite = new CSprite(*m_pResourceManager->GetSprite(ID_SPRITE_BIG_EXPLOSION));
		if (timeLive == 0.0f)
			m_fTimeLive = 0.39f;
		else
			m_fTimeLive = timeLive;
		break;
	case ID_BULLET_EXPLOSION:
		m_pSprite = new CSprite(*m_pResourceManager->GetSprite(ID_SPRITE_BULLET_EXPLOSION));
		if (timeLive == 0.0f)
			m_fTimeLive = 0.05f;
		else
			m_fTimeLive = timeLive;
		break;
	case ID_ENEMY_EXPLOSION:
		m_pSprite = new CSprite(*m_pResourceManager->GetSprite(ID_SPRITE_ENEMY_EXPLOSION));
		if (timeLive == 0.0f)
			m_fTimeLive = 0.28f;
		else
			m_fTimeLive = timeLive;
		break;
	case ID_ENEMY_FALL_IN_WATER:
		m_pSprite = new CSprite(*m_pResourceManager->GetSprite(ID_SPRITE_ENEMY_FALL_IN_WATER));
		if (timeLive == 0.0f)
			m_fTimeLive = 0.28f;
		else
			m_fTimeLive = timeLive;
		break;
	}
}

CExplosion::~CExplosion()
{

}

void CExplosion::Update(float timeFrame)
{
	if (!m_bIsLive)
		return;

	if (m_fTimeLive >= 0)
	{
		m_fTimeLive -= timeFrame;
	}
	else
		this->Kill();
	m_pSprite->Update(timeFrame);
	UpdateBox(timeFrame);
}